<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use DateTimeInterface;
class Order extends Model
{
    use HasFactory;
    protected $appends = [
        'pre_service_price',//预计精选服务价格PreServicePrice
        'pre_brokerage',//预计手续费价格 PreBrokerage
        'pre_base_price',//基础服务费 PreBasePrice
        'fact_service_price',//实际精选服务费 FactServicePrice
        'fact_brokerage',//实际手续费 FactBrokerage
        'fact_base_price'//实际基础服务费 FactBasePrice
        //fact_lease_price//实际租金
    ];
    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }
    protected $guarded = [];
    public function car(){
        return $this->hasOne(Car::class,'id','car_id');
    }

    public function coupon(){
        return $this->hasOne(Coupon::class,'id','coupon_id');
    }
    public function service(){
        return $this->hasMany(OrderService::class,'order_sn','order_sn');
    }
    public function user(){
        return $this->belongsTo(User::class,'openid','openid');
    }
    public function getPreServicePriceAttribute()
    {
        return $this->attributes['pre_service_price'] = $this->service_price*$this->pre_lease_days;
    }
    //pre_brokerage
    public function getPreBrokerageAttribute(){
        return $this->attributes['pre_brokerage'] = $this->brokerage*$this->pre_lease_days;
    }
    //pre_base_price
    public function getPreBasePriceAttribute(){
        return $this->attributes['pre_base_price'] = $this->base_price*$this->pre_lease_days;
    }
    //fact_service_price
    public function getFactServicePriceAttribute(){
        return $this->attributes['fact_service_price'] = $this->service_price*$this->lease_days;
    }
    //fact_brokerage
    public function getFactBrokerageAttribute(){
        return $this->attributes['fact_brokerage'] = $this->brokerage*$this->lease_days;
    }
    //fact_base_price
    public function getFactBasePriceAttribute(){
        return $this->attributes['fact_brokerage'] = $this->base_price*$this->lease_days;
    }



}
